package top.zhangjianyong.tools.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import top.zhangjianyong.tools.entity.RemindItem;
import top.zhangjianyong.tools.service.mybatis.IRemindItemService;

import java.time.LocalDateTime;

/**
 * @author ： zhangjianyong
 * @date ： 2022/10/9 4:26 PM
 */
@Component
public class RemindUtil {

    @Value("${close-url}")
    private String CLOSE_URL;
    @Autowired
    private IRemindItemService iRemindItemService;

    /**
     * 发送提醒邮件
     *
     * @param remindItem
     * @throws Exception
     */
    public void sendEmail(RemindItem remindItem) throws Exception {
        MailUtil.send(remindItem.getEmail(),
                "提醒：" + remindItem.getName() + ",时间：" + LocalDateTime.now(),
                remindItem.getContent()+"\n请点击关闭提醒：" + CLOSE_URL + "?id=" + remindItem.getId()
                        + "&uuid=" + remindItem.getUuid());

    }

    /**
     * 发送提醒邮件一次关闭
     *
     * @param remindItem
     * @throws Exception
     */
    public void sendEmailAndClose(RemindItem remindItem) throws Exception {

        MailUtil.send(remindItem.getEmail(),
                "提醒：" + remindItem.getName() + ",时间：" + LocalDateTime.now(),
                remindItem.getContent()+"\n非工作日，提醒自动关闭");
        iRemindItemService.close(remindItem.getId(), remindItem.getUuid());
    }
}
